package com.wx.tgp.socket.demo.stream;

import java.io.*;

/**
 * InputStream
 */
public class InputStreamDemo {

    public static void main(String[] args) {
        FileInputStream fis = null;
        BufferedInputStream bin = null;
        byte[] sum = null;
        try {
            fis = new FileInputStream("c:/demo.txt");
            bin = new BufferedInputStream(fis);
            while(true) {
                int count = fis.available();
                if(count>0) {
                    byte[] input = new byte[count];
                    sum = new byte[count];
                    bin.read(sum);
                    System.out.println(new String(sum));
                }else {
                    break;
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            if(fis!=null){
                try{
                    fis.close();
                    bin.close();
                }catch (IOException e1){
                }
            }
        } finally {
            // 在最后把IO流关闭
            if(fis!=null){
                try{
                    fis.close();
                    bin.close();
                }catch (IOException e1){
                }
            }
        }
    }
}
